import { useEffect, useState } from 'react';
import { setMailRead } from '@/services/mail';

// 邮件标记为已读
const useSetMailRead = query => {
    const [loading, setLoading] = useState(false);
    const [resData, setResData] = useState(null);

    const fetchData = async () => {
        setLoading(true);
        const { code } = await setMailRead(query);
        if (code === 10000) {
            setResData(query.id);
        } else {
            setResData(null);
        }
        setLoading(false);
    };
    useEffect(() => {
        if (query) {
            fetchData();
        }
    }, [query]);
    return { loading, resData };
};

export default useSetMailRead;
